<template>
  <div>
    <el-card class="box-card margin_30">
      <div slot="header" class="clearfix">
        <span>条件查询</span>
      </div>
      <el-form :model="orderInfo" label-width="80px" :inline="true" size="mini">
        <el-form-item label="订单编号">
          <el-input v-model="orderInfo.orderSn" placeholder="请填写订单编号" />
        </el-form-item>
        <el-form-item label="退单状态">
          <el-select v-model="orderInfo.status" placeholder="退单状态">
            <el-option
              label="待处理"
              value="0"
            />
            <el-option
              label="退货中"
              value="1"
            />
            <el-option
              label="已完成"
              value="2"
            />
            <el-option
              label="已拒绝"
              value="3"
            />
          </el-select>
        </el-form-item>
        <el-button size="mini" @click="reset">重置</el-button>
        <el-button size="mini" type="primary" @click="search">搜索</el-button>
      </el-form>
    </el-card>
    <el-card class="box-card margin_30">
      <div>
        <el-table
          :data="returnList"
          border
          style="width: 100%"
        >
          <el-table-column
            type="index"
            label="#"
            fixed="left"
            width="50"
            align="center"
          />
          <el-table-column
            prop="orderSn"
            label="订单编号"
            align="center"
            width="250"
          />
          <el-table-column
            label="退单状态"
            width="180"
            align="center"
          >
            <template slot-scope="scope">
              <el-button v-if="scope.row.status == 0" size="small">
                待处理
              </el-button>
              <el-button v-else-if="scope.row.status == 1" size="small">
                退货中
              </el-button>
              <el-button v-if="scope.row.status == 2" size="small">
                已完成
              </el-button>
              <el-button v-else-if="scope.row.status == 3" size="small">
                已拒绝
              </el-button>
            </template>
          </el-table-column>

          <el-table-column
            prop="description"
            label="描述"
            align="center"
            width="200"
          />

          <el-table-column
            prop="reason"
            label="退单原因"
            align="center"
            width="200"
          />
          <el-table-column
            prop="productName"
            label="商品名称"
            align="center"
            width="200"
          />

          <el-table-column
            prop="productAttr"
            label="商品属性"
            align="center"
            width="200"
          />
          <el-table-column
            prop="handleNote"
            label="商家备注"
            align="center"
            width="200"
          />
          <el-table-column
            prop="createTime"
            label="添加时间"
            align="center"
            width="200"
          />
          <el-table-column
            prop=""
            label="操作"
            fixed="right"
            align="center"
            width="150"
          >
            <template slot-scope="scope">
              <el-button icon="el-icon-view" type="primary" size="small" @click="goReturnDetail(scope.row.id)">查看订单</el-button>
            </template>

          </el-table-column>
        </el-table>
        <el-pagination
          :current-page="start"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="limit"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </el-card>
  </div>
</template>

<script>
import { findReturnApply } from '@/api/orderManage/returnList/index'
import mixins from '@/mixins/index'
export default {
  name: 'VueAdminTemplateMasterIndex',
  mixins: [mixins],
  data() {
    return {
      orderInfo: {
        'createTime': '',
        'handleTime': '',
        'memberUsername': '',
        'orderId': '',
        'orderSn': '',
        'status': ''
      },

      returnList: []
    }
  },

  created() {
    this.init()
  },

  mounted() {

  },

  methods: {
    goReturnDetail(id) {
      this.$router.push(`/orderManage/returnDetail/?id=${id}`)
    },
    search() {
      this.init()
    },
    reset() {
      var obj = {
        'createTime': '',
        'handleTime': '',
        'memberUsername': '',
        'orderId': '',
        'orderSn': '',
        'status': ''
      }
      this.orderInfo = obj
      this.init()
    },
    init() {
      findReturnApply(this.start, this.limit, this.orderInfo).then(res => {
        res.data.rows.forEach(ele => {
          var str = ''
          JSON.parse(ele.productAttr).forEach(itm => {
            console.log(itm)
            str += itm.key + ':' + itm.value + ' '
            console.log(str)
          })
          ele.productAttr = str
        })
        this.returnList = res.data.rows
      })
    }
  }
}
</script>

<style scoped>

</style>
